<?php

	class Scope {
		
		public function __construct() { }
		
		public static function loadVar($name) { 
			
			if( self::loadGetVar($name) != null ) {
				return self::loadGetVar($name);
			} else if( self::loadPostVar($name) != null ) {
				return self::loadPostVar($name);
			} else if( self::loadCookieVar($name) != null ) {
				return self::loadCookieVar($name);
			} else if( self::loadSessionVar($name) != null ) {
				return self::loadSessionVar($name);
			} else if( self::loadEnvVar($name) != null ) {
				return self::loadEnvVar($name);
			}else if( self::loadCookieVar($name) != null ) {
				return self::loadCookieVar($name);
			} else {
				return null;
			}
		}
		
		public static function loadPostVar($name) {
			return isset($_POST[$name]) ? $_POST[$name] : null;
		}
		
		public static function loadGetVar($name) {
			return isset($_GET[$name]) ? $_GET[$name] : null;
		}
		
		public static function loadSessionVar($name) {
			@session_start();
			return isset($_SESSION[$name]) ? $_SESSION[$name] : null;
		}
		
		public static function loadCookieVar($name) {
			return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
		}

		public static function loadEnvVar($name) {
			$value = getenv($name);
			return isset($value) ? $value : null;
		}
		
		public static function putCookieVar($name,$value) {
			$_COOKIE[$name] = $value;
		}
		
		public static function putPostVar($name,$value) {
			$_POST[$name] = $value;
		}
		
		public static function putGetVar($name,$value) {
			$_GET[$name] = $value;
		}
		
		public static function putSessionVar($name,$value) {
			session_start();
			$_SESSION[$name] = $value;
			session_write_close();
		}
		
		public static function putEnvVar($name, $value) {
			putenv($name . "=" . $value);
		}
		
		public static function getLocale() {
			$name = "LANG";
			$lang = self::loadVar($name);
			if( $lang != null ) {
				return $lang; 
			} else {
				$arr = FileUtils::loadPropertyInArray("include/config/config.properties");
				$lang = $arr["appconfig.default.locale"]; 
				self::putEnvVar($name,$lang);
				return $lang;	
			}
		}
	}
?>